package com.zl.rockemqsource.psvmtest;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

/**
 * @Author: zhouliang
 * @Date: 2019/6/28 9:40
 */
public class Producer {
    private static final String PRODUCE_GROUP = "test_quick_producer_name";
    private static final String NAME_SERVER = "localhost:9876";

    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
        DefaultMQProducer producer = new DefaultMQProducer(PRODUCE_GROUP);
        producer.setNamesrvAddr(NAME_SERVER);
        producer.start();
        for (int i = 0; i < 5; i++) {
            Message message = new Message("test_quick_topic",
                    "TagA",
                    "key" + i,
                    ("hello rocketMq" + i).getBytes());
            //同步发送消息
            if (i == 1) {
                message.setDelayTimeLevel(3);
            }
            SendResult send = producer.send(message);
            System.err.println(send.getSendStatus());
        }
        producer.shutdown();
    }
}
